package gdconf

import (
	"server_cluster/common/logger"
)

type ConfigQuest struct {
	Id            int32         `csv:"ID" gorm:"primary_key;autoIncrement:false"` // 任务id
	CondList      IntArrayArray `csv:"Finish_condition,omitempty"`                // 任务完成条件
	Scene         int32         `csv:"Scene,omitempty"`                           // 场景id
	EventList     IntArrayArray `csv:"Event_list,omitempty"`                      // 主线任务完成后触发事件
	Reward        int32         `csv:"Reward,omitempty"`                          // 奖励id
	ParentQuestId int32         `csv:"-"`
}

func (t *ConfigQuest) TableName() string {
	return "config_quest"
}

func (g *GameDataConfig) saveQuest() {
	saveTableToDb[ConfigQuest](g.Db, readTable[ConfigQuest](g.CsvPathPrefix+"Task.csv"))
}

func (g *GameDataConfig) loadQuestConfig() {
	g.GameDataMaps.QuestMap = make(map[int32]*ConfigQuest)
	for _, Quest := range loadTableFromDb[ConfigQuest](g.Db) {
		g.GameDataMaps.QuestMap[Quest.Id] = Quest
	}
	logger.Info("ConfigQuest Count: %v", len(g.GameDataMaps.QuestMap))
}

func GetConfigQuest(id int32) *ConfigQuest {
	data, ok := CONF.GameDataMaps.QuestMap[id]
	if !ok {
		return nil
	}
	return data
}

func GetConfigQuestMap() map[int32]*ConfigQuest {
	return CONF.GameDataMaps.QuestMap
}
